package com.hera.process.config.rest.delegate.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import com.hera.base.domain.WrapperJSON;
import com.hera.base.rest.delegate.BaseDelegate;
import com.hera.base.util.FiltroDTO;
import com.hera.process.config.rest.delegate.ExternalDelegate;
import com.hera.process.external.domain.AddTableDetail;
import com.hera.process.external.domain.AddTableIndex;
import com.hera.process.external.domain.AdditionalTable;

@Service
public class ExternalDelegateImpl extends BaseDelegate implements ExternalDelegate{

	@Autowired
	private RestTemplate restTemplate;
	
	@Value("${url.contexto.external}")
	private String urlController;
	
	@Value("${url.base}")
	private String urlBase;
	
	
	
	/*
	///////////////////////////////////////////////////////////////////////////////////
	 /////////////////////////////// ADDITIONALTABLE ///////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////
	*/
	
	@Override
	public List<AdditionalTable> findAllAdditionalTables(FiltroDTO filtroDTO) {
	
        
        return postForObject(urlBase+urlController+"additionaltable/list", filtroDTO, 
        		new ParameterizedTypeReference<WrapperJSON<List<AdditionalTable>>>() {});
	}

	@Override
	public AdditionalTable createAdditionalTable(AdditionalTable addtable) {
	
		 return postForObject(urlBase+urlController+"additionaltable/save", addtable, 
	        		new ParameterizedTypeReference<WrapperJSON<AdditionalTable>>() {});
	}

	@Override
	public AdditionalTable updateAdditionalTable(AdditionalTable addtable) {
		return postForObject(urlBase+urlController+"additionaltable/update", addtable, 
	        		new ParameterizedTypeReference<WrapperJSON<AdditionalTable>>() {});
	}

	@Override
	public void deleteAdditionalTable(AdditionalTable addtable) {
		
		postForObject(urlBase+urlController+"additionaltable/delete", addtable, 
        		new ParameterizedTypeReference<WrapperJSON<AdditionalTable>>() {});
	}
	
	/*
	///////////////////////////////////////////////////////////////////////////////////
	 /////////////////////////////// ADDTABLESDETAIL ///////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////
	*/

	@Override
	public List<AddTableDetail> findAllAddTableDetails(FiltroDTO filtroDTO) {
	
        return postForObject(urlBase+urlController+"adddetail/list", filtroDTO, 
        		new ParameterizedTypeReference<WrapperJSON<List<AddTableDetail>>>() {});
	}

	@Override
	public AddTableDetail createAddTableDetail(AddTableDetail adddetail) {
		
		
		return postForObject(urlBase+urlController+"adddetail/save", adddetail, 
        		new ParameterizedTypeReference<WrapperJSON<AddTableDetail>>() {});
	}

	@Override
	public AddTableDetail updateAddTableDetail(AddTableDetail adddetail) {
		return postForObject(urlBase+urlController+"adddetail/update", adddetail, 
        		new ParameterizedTypeReference<WrapperJSON<AddTableDetail>>() {});
	}

	@Override
	public void deleteAddTableDetail(AddTableDetail adddetail) {
		
		postForObject(urlBase+urlController+"adddetail/delete", adddetail, 
        		new ParameterizedTypeReference<WrapperJSON<AddTableDetail>>() {});
	}
	
	/*
	///////////////////////////////////////////////////////////////////////////////////
	 /////////////////////////////// ADDTABLEINDEX ///////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////
	*/

	@Override
	public List<AddTableIndex> findAllAddTableIndexs(FiltroDTO filtroDTO) {

        
        return postForObject(urlBase+urlController+"addtableindex/list", filtroDTO, 
        		new ParameterizedTypeReference<WrapperJSON<List<AddTableIndex>>>() {});
	}

	@Override
	public AddTableIndex createAddTableIndex(AddTableIndex addindex) {
		
        return postForObject(urlBase+urlController+"addtableindex/save", addindex, 
        		new ParameterizedTypeReference<WrapperJSON<AddTableIndex>>() {});
	}

	@Override
	public AddTableIndex updateAddTableIndex(AddTableIndex addindex) {
		return postForObject(urlBase+urlController+"addtableindex/update", addindex, 
	        		new ParameterizedTypeReference<WrapperJSON<AddTableIndex>>() {});
	}

	@Override
	public void deleteAddTableIndex(AddTableIndex addindex) {
		
		postForObject(urlBase+urlController+"addtableindex/delete", addindex, 
        		new ParameterizedTypeReference<WrapperJSON<AddTableIndex>>() {});
	}
	
	@Override
	public Map<String, Object> insertMetadata(Map<String, Object> entity){
		return postForObject(urlBase+urlController+"metadata/insert", entity, 
        		new ParameterizedTypeReference<WrapperJSON<Map<String, Object>>>() {});
	}
	
	@Override
	public Map<String, Object> selectMetadataById(List<Object> fields){
		return postForObject(urlBase+urlController+"metadata/selectbyid", fields, 
        		new ParameterizedTypeReference<WrapperJSON<Map<String, Object>>>() {});
	}
	
	
}
